#include "ScnsDht11.c.h"

#if defined(SCNS_DHT11_ENABLE)&&SCNS_DHT11_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsMath.h"

ScnsStatus scnsBspDht11PostInit(ScnsDht11Enum dhtN)
{
    scnsMenuSetPage(3,"dht11",NULL);
    scnsMenuAddConstStruct(3,scnsDht11Result[dhtN],temperature,,SCNS_TYPE_UINT8);
    scnsMenuAddConstStruct(3,scnsDht11Result[dhtN],humidity,,SCNS_TYPE_UINT8);
    return SCNS_STATUS_OK;
}

void scnsBspDht11SetDir(ScnsDht11Enum dhtN,uint8 in)
{
    const uint32 hb=scnsMathGetHighest1(ONE_WIRE_Pin);
    if(hb<8)
    {
        const uint32 of=hb*4;
        ONE_WIRE_GPIO_Port->CRL&=~((0XF)<<(of));
        ONE_WIRE_GPIO_Port->CRL|=((in?4:3)<<(of));
    }
    else
    {
        const uint32 of=(hb-8)*4;
        ONE_WIRE_GPIO_Port->CRH&=~((0XF)<<(of));
        ONE_WIRE_GPIO_Port->CRH|=((in?4:3)<<(of));
    }
}

void scnsBspDht11Set(ScnsDht11Enum dhtN,uint8 dat)
{
    ONE_WIRE_GPIO_Port->BSRR=(dat)?(ONE_WIRE_Pin):(ONE_WIRE_Pin<<16);
}

uint8 scnsBspDht11Get(ScnsDht11Enum dhtN)
{
    return (ONE_WIRE_GPIO_Port->IDR&ONE_WIRE_Pin)?1:0;
}

#endif
